package com.zy.Reflect;

import org.junit.Test;

import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Properties;

public class ReflectTest2
{
    @Test
    public void Test()
    {
        //1、获取类加载器
        ClassLoader classLoader = ReflectTest1.class.getClassLoader();
        //2\加载配置文件进内存
        InputStream resourceAsStream = classLoader.getResourceAsStream("reflect.properties");
        Properties properties=new Properties();
        try
        {
            properties.load(resourceAsStream);
            String className=properties.getProperty("className");
            String method=properties.getProperty("method");
            Class<ReflectTest1> reflectTestClass = ReflectTest1.class;

            //3、加载该类进内存
            Class<?> aClass = Class.forName(className);
            Object o = aClass.newInstance();
            Method method1 = aClass.getMethod(method);
            method1.invoke(o);

        } catch (IOException | ClassNotFoundException | NoSuchMethodException e)
        {
            e.printStackTrace();
        } catch (IllegalAccessException e)
        {
            e.printStackTrace();
        } catch (InstantiationException e)
        {
            e.printStackTrace();
        } catch (InvocationTargetException e)
        {
            e.printStackTrace();
        }

    }
}
